package cn.tedu.eb_film.controller;

import cn.tedu.eb_film.pojo.dto.*;
import cn.tedu.eb_film.pojo.dto.CinemaScheduleAddNewDTO;
import cn.tedu.eb_film.pojo.vo.*;
import cn.tedu.eb_film.service.CinemaScheduleService;
import cn.tedu.eb_film.utils.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * 场次控制类
 *
 * @author zhongcongwen
 * @since 2023/3/24 19:21
 */
@Slf4j
@RestController
@Api(tags = "电影场次管理模块")
@RequestMapping("cinemaSchedule")
public class cinemaScheduleController {
    @Autowired
    private CinemaScheduleService cinemaScheduleService;

    @PostMapping("addNew")
    @ApiOperation("添加场次")
    @ApiOperationSupport(order = 100)
    public JsonResult<Void> addNew(@RequestBody CinemaScheduleAddNewDTO addNewDTO) {
        log.debug("开始处理新增场次数据");
        System.out.println("addNewDTO = " + addNewDTO);
        cinemaScheduleService.addNew(addNewDTO);
        return JsonResult.ok();
    }

    @PostMapping("addNews")
    @ApiOperation("批量添加场次数据")
    @ApiOperationSupport(order = 110)
    public JsonResult<Void> addNews(@RequestBody List<CinemaScheduleAddNewDTO> addNewDTOs) {
        log.debug("开始处理新增场次数据");
        cinemaScheduleService.addNews(addNewDTOs);
        return JsonResult.ok();
    }

    @PostMapping("{id}/delete")
    @ApiOperation("根据id删除场次数据")
    @ApiOperationSupport(order = 200)
    public JsonResult<Void> deleteById(@PathVariable Long id) {
        log.debug("开始根据id删除场次数据");
        cinemaScheduleService.deleteById(id);
        return JsonResult.ok();
    }

    @PostMapping("deletes")
    @ApiOperation("批量删除数据")
    @ApiOperationSupport(order = 210)
    public JsonResult<Void> deleteById(@RequestBody List<Long> ids) {
        log.debug("开始根据ids删除场次数据");
        cinemaScheduleService.deleteByIds(ids);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/enable")
    public JsonResult<Void> setEnable(@PathVariable Long id) {
        log.debug("开始处理[启用场次],参数场次id:{}", id);
        cinemaScheduleService.setEnable(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id}/disable")
    public JsonResult<Void> setDisable(@PathVariable Long id) {
        log.debug("开始处理[禁用场次],参数场次id:{}", id);
        cinemaScheduleService.setDisable(id);
        return JsonResult.ok();
    }


    @PostMapping("{id}/get")
    @ApiOperation("根据id获取数据")
    @ApiOperationSupport(order = 300)
    public JsonResult<CinemaScheduleStandardVO> get(@PathVariable Long id) {
        log.debug("开始根据id查询数据");
        final CinemaScheduleStandardVO cinemaScheduleStandardVO = cinemaScheduleService.getCinemaScheduleById(id);
        return JsonResult.ok(cinemaScheduleStandardVO);
    }

    @PostMapping("{id}/list")
    @ApiOperation("查询场次数据列表")
    @ApiOperationSupport(order = 310)
    public JsonResult<List<CinemaScheduleListItemVO>> list() {
        log.debug("开始根据id查询数据");
        final List<CinemaScheduleListItemVO> list = cinemaScheduleService.list();
        return JsonResult.ok(list);
    }

    @PostMapping("upload")
    @ApiOperation("更新场次数据")
    @ApiOperationSupport(order = 400)
    public JsonResult<Void> upload(@RequestBody CinemaScheduleUpdateInfoDTO cinemaScheduleUpdateInfoDTO) {
        log.debug("开始根据id查询数据");
        cinemaScheduleService.update(cinemaScheduleUpdateInfoDTO);
        return JsonResult.ok();
    }

    @GetMapping("{cinemaHallId}/listByHallId")
    public JsonResult<List<CinemaScheduleListItemVO>> listByCinemaMallId(
            @PathVariable Long cinemaHallId
    ) {
        log.debug("开始处理[根据影厅查询场次],参数影厅id:{}", cinemaHallId);
        List<CinemaScheduleListItemVO> list = cinemaScheduleService.listByCinemaHallId(cinemaHallId, 1);
        return JsonResult.ok(list);
    }

    @PostMapping("edit")
    @ApiOperation("更新场次数据")
    @ApiOperationSupport(order = 420)
    public JsonResult<Void> upload(@RequestBody CinemaScheduleEditDTO cinemaScheduleEditDTO) {
        log.debug("开始根据id查询数据");
        cinemaScheduleService.editSchedule(cinemaScheduleEditDTO);
        return JsonResult.ok();
    }
}
